<template>
	<view style="height: 100vh;" :style="{'fontFamily':themeColor.typeface,'color':themeColor.main_font_color}">
		<u-sticky offset-top="0">
			<nuoyu-header :title="'订单详情'"></nuoyu-header>
		</u-sticky>
		<view class="nuoyu-index">
			<view>
				<view class="tabs_box" >
					<view v-for="(item,index) in tabList" >
						<view @click="selectTabs(item,index)" :style="{'--main-bg-color':themeColor.main_color}" :class="item.class">{{item.name}}</view>
					</view>
					
				</view>
				<view class="address_box" :style="{'--main-bg-color':themeColor.main_color}" @click="storeShowAddress=true">
					<view v-if="addressData">
						<view style="display: flex;gap: 12rpx;">
							<span>
								<svg t="1750134472568" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4356" width="18" height="18"><path d="M451.673935 994.395699C478.883834 1025.019147 524.254807 1024.808979 551.400292 993.928851 553.755808 991.387908 558.821323 985.796762 565.872444 977.84835 577.572838 964.659017 590.597131 949.62432 604.615947 932.998315 644.662065 885.504506 684.708678 834.717818 722.129538 782.646447 759.658524 730.424619 792.492213 679.709274 819.314991 631.458462 868.685946 542.646317 896 465.543426 896 402.285715 896 180.109449 719.301715 0 501.333333 0 283.364952 0 106.666667 180.109449 106.666667 402.285715 106.666667 465.598716 134.05152 542.80573 183.54613 631.762622 210.371803 679.976529 243.193308 730.651876 280.699364 782.833154 318.155192 834.94455 358.239268 885.77421 398.322835 933.311031 412.354743 949.952073 425.391185 965.00073 437.102468 978.202579 444.160087 986.158466 449.230214 991.754921 451.982775 994.736706L451.673935 994.395699ZM486.822684 961.321348C484.281231 958.568254 479.425084 953.207989 472.585916 945.498359 461.135889 932.591017 448.364015 917.847761 434.602351 901.527215 395.275714 854.888073 355.949587 805.019548 319.289224 754.014863 282.808749 703.260452 250.983685 654.123578 225.158316 607.707522 179.388826 525.445805 154.50505 455.290161 154.50505 402.285715 154.50505 207.039905 309.785362 48.761905 501.333333 48.761905 692.881306 48.761905 848.161617 207.039905 848.161617 402.285715 848.161617 455.246022 823.345286 525.298263 777.693969 607.419251 751.873483 653.867066 720.038415 703.039925 683.537446 753.831262 646.912604 804.794967 607.624538 854.619674 568.335977 901.215038 554.587654 917.520243 541.828177 932.24925 530.389289 945.143797 523.556841 952.845711 518.705521 958.200435 516.166694 960.950526 507.543772 970.748911 495.255793 970.80583 487.131524 961.662353L486.822684 961.321348Z" fill="#ffffff" p-id="4357"></path><path d="M714.955981 467.028806C723.919106 442.627955 728.565658 416.668998 728.565658 390.095238 728.565658 268.908183 632.184774 170.666667 513.29293 170.666667 394.401086 170.666667 298.020202 268.908183 298.020202 390.095238 298.020202 511.282291 394.401086 609.52381 513.29293 609.52381 549.003859 609.52381 583.510052 600.631947 614.373097 583.874409 626.032316 577.543868 630.449257 562.77782 624.238611 550.893519 618.027966 539.009218 603.541579 534.507006 591.882359 540.837549 567.900883 553.858639 541.111735 560.761905 513.29293 560.761905 420.821495 560.761905 345.858586 484.351836 345.858586 390.095238 345.858586 295.838641 420.821495 219.428572 513.29293 219.428572 605.764365 219.428572 680.727273 295.838641 680.727273 390.095238 680.727273 410.807981 677.117041 430.977316 670.154965 449.930592 665.522846 462.540883 671.796821 476.591108 684.168282 481.312651 696.53974 486.034191 710.323861 479.639095 714.955981 467.028806L714.955981 467.028806Z" fill="#ffffff" p-id="4358"></path></svg>
							</span>
							<text style="margin-right: 15rpx;">{{addressData.name}}</text>
							<text style="margin-right: 15rpx;">{{addressData.phone}}</text>
							<text>{{addressData.address}}</text>
						</view>
						<view style="margin-left: 48rpx;">{{addressData.moreAddres}}</view>
					</view>
					<view v-else>
						<view style="display: flex;gap: 12rpx;">
							<span>
								<svg t="1750134472568" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4356" width="18" height="18"><path d="M451.673935 994.395699C478.883834 1025.019147 524.254807 1024.808979 551.400292 993.928851 553.755808 991.387908 558.821323 985.796762 565.872444 977.84835 577.572838 964.659017 590.597131 949.62432 604.615947 932.998315 644.662065 885.504506 684.708678 834.717818 722.129538 782.646447 759.658524 730.424619 792.492213 679.709274 819.314991 631.458462 868.685946 542.646317 896 465.543426 896 402.285715 896 180.109449 719.301715 0 501.333333 0 283.364952 0 106.666667 180.109449 106.666667 402.285715 106.666667 465.598716 134.05152 542.80573 183.54613 631.762622 210.371803 679.976529 243.193308 730.651876 280.699364 782.833154 318.155192 834.94455 358.239268 885.77421 398.322835 933.311031 412.354743 949.952073 425.391185 965.00073 437.102468 978.202579 444.160087 986.158466 449.230214 991.754921 451.982775 994.736706L451.673935 994.395699ZM486.822684 961.321348C484.281231 958.568254 479.425084 953.207989 472.585916 945.498359 461.135889 932.591017 448.364015 917.847761 434.602351 901.527215 395.275714 854.888073 355.949587 805.019548 319.289224 754.014863 282.808749 703.260452 250.983685 654.123578 225.158316 607.707522 179.388826 525.445805 154.50505 455.290161 154.50505 402.285715 154.50505 207.039905 309.785362 48.761905 501.333333 48.761905 692.881306 48.761905 848.161617 207.039905 848.161617 402.285715 848.161617 455.246022 823.345286 525.298263 777.693969 607.419251 751.873483 653.867066 720.038415 703.039925 683.537446 753.831262 646.912604 804.794967 607.624538 854.619674 568.335977 901.215038 554.587654 917.520243 541.828177 932.24925 530.389289 945.143797 523.556841 952.845711 518.705521 958.200435 516.166694 960.950526 507.543772 970.748911 495.255793 970.80583 487.131524 961.662353L486.822684 961.321348Z" fill="#ffffff" p-id="4357"></path><path d="M714.955981 467.028806C723.919106 442.627955 728.565658 416.668998 728.565658 390.095238 728.565658 268.908183 632.184774 170.666667 513.29293 170.666667 394.401086 170.666667 298.020202 268.908183 298.020202 390.095238 298.020202 511.282291 394.401086 609.52381 513.29293 609.52381 549.003859 609.52381 583.510052 600.631947 614.373097 583.874409 626.032316 577.543868 630.449257 562.77782 624.238611 550.893519 618.027966 539.009218 603.541579 534.507006 591.882359 540.837549 567.900883 553.858639 541.111735 560.761905 513.29293 560.761905 420.821495 560.761905 345.858586 484.351836 345.858586 390.095238 345.858586 295.838641 420.821495 219.428572 513.29293 219.428572 605.764365 219.428572 680.727273 295.838641 680.727273 390.095238 680.727273 410.807981 677.117041 430.977316 670.154965 449.930592 665.522846 462.540883 671.796821 476.591108 684.168282 481.312651 696.53974 486.034191 710.323861 479.639095 714.955981 467.028806L714.955981 467.028806Z" fill="#ffffff" p-id="4358"></path></svg>
							</span>
							请设置收货地址
						</view>
						<!-- <view style="display: flex;justify-content: center;align-items: center;">
							<image style="width: 52rpx;height: 52rpx;" src="/static/nuoyu-goods/right.png" mode="aspectFill"></image>
						</view> -->
					</view>
				</view>
				<view class="goods_card" v-if="orderDetails.goods_sku || orderDetails.goods_info">
					<view class="card_top">
						<view class="left_img">
							<u--image
								v-if="orderDetails.goods_sku.skuImage"
								:src="orderDetails.goods_sku.skuImage"
								width="80"
								height="80"
							></u--image>
							<u--image
								v-else
								:src="orderDetails.goods_info.previewUrl"
								width="80"
								height="80"
							></u--image>
						</view>
						<view class="right_text">
							<view class='text_title'>{{orderDetails.goods_info.goodsName}}</view>
							<view style="color: #ccc;font-weight: bold;">{{orderDetails.goods_sku.skuName}}</view>
							<view class="text_number">
								<span v-if="orderDetails.goods_sku.skuPrice" >￥{{orderDetails.goods_sku.skuPrice}}</span>
								<span v-else="orderDetails.goods_info.goodsPrice" :style="{color:themeColor.main_color}" >￥{{orderDetails.goods_info.goodsPrice}}</span>
								<span><u-number-box inputWidth="100px" v-model="orderDetails.goodsQuantity"></u-number-box></span>
							</view>
						</view>
					</view>
					<view class="card_bottom">
						<u--form
							labelPosition="left"
							:model="goodsForm"
						>
							<u-form-item
								label="备注"
								prop="memo"
							>
								<u--input
									v-model="goodsForm.memo"
									border="none"
									inputAlign="right"
									placeholder="请先与商家沟通一致再留言哦~"
								></u--input>
								
							</u-form-item>
						</u--form>
					</view>
				</view>
				<view class="goods_info">
					<u--form
						labelPosition="left"
						:model="goodsForm"
					>
						<u-form-item
							label="优惠券"
							prop="memo"
							label-width="120px"
							@click="couponsShow = true"
						>
							<view style="display:flex;justify-content: space-between;width: 100%;" @click="couponsData.length?couponsShow = true:couponsShow = false">
								<view></view>
								<!-- <view>{{couponsData.length?'有优惠券可使用哦':'暂无优惠券可使用'}}</view> -->
								<view v-if="selectCoupons.moneys">-{{ selectCoupons.moneys }}</view>
								<view v-else>请选择优惠券</view>
							</view>
						</u-form-item>
						<u-form-item
							label="运费"
							label-width="120px"
							v-if="orderDetails.goods_info"
						>
							<view style="display: flex;justify-content: space-between;width: 100%;">
								<view></view>
								<view>{{orderDetails.goods_info.distributionFee ? '￥' + orderDetails.goods_info.distributionFee : '包邮'}}</view>
							</view>
						</u-form-item>
						<u-form-item
							label="实际支付金额"
							prop="actual_money"
							label-width="120px"
							 v-if="orderDetails.goods_sku || orderDetails.goods_info"
						>
						<view v-if="orderDetails.goods_info.goodsSkuType=='多规格'" style="display: flex;justify-content: space-between;width: 100%;">
							<view></view>
							<view>￥{{compPrice}}</view>
							<!-- <view>￥{{selectCoupons.moneys || orderDetails.goods_info.distributionFee ? '￥'+ goodsForm.actual_money : orderDetails.goods_sku.skuPrice}}</view> -->
						</view>
						<view v-else style="display: flex;justify-content: space-between;width: 100%;">
							<view></view>
							<view>￥{{compPrice}}</view>
							<!-- <view>￥{{selectCoupons.moneys || orderDetails.goods_info.distributionFee ? '￥'+ goodsForm.actual_money : orderDetails.goods_info.goodsPrice}}</view> -->
						</view>
							<!-- <u--input
								v-if="orderDetails.goods_sku.skuPrice"
								:value="selectCoupons.moneys || orderDetails.goods_info.distributionFee ? '￥'+ goodsForm.actual_money : orderDetails.goods_sku.skuPrice"
								border="none"
								inputAlign="right"
							></u--input>
							<u--input
								v-else
								:value="selectCoupons.moneys || orderDetails.goods_info.distributionFee ? '￥'+ goodsForm.actual_money : orderDetails.goods_info.goodsPrice"
								border="none"
								inputAlign="right"
							></u--input> -->
						</u-form-item>
						<u-form-item
							label="支付方式"
							prop="paypal_type"
							label-width="120px"
						>
							<u-picker @confirm="changePay" :show="typeShow" :columns="paypalCol" @cancel="typeShow = false">
							</u-picker>
							<!-- <span @click="typeShow = true">{{ goodsTypeText }}</span> -->
							
							<view @click="typeShow = true" style="display: flex;">
								<span>{{ goodsTypeText }}</span>
								<u-icon
									name="arrow-right"
								></u-icon>
								
							</view>
							
						</u-form-item>
						<u-form-item
							label="开具发票"
							prop="invoice"
							label-width="120px"
						>
							<u--input
								v-model="goodsForm.invoice"
								border="none"
								inputAlign="right"
								placeholder="暂无"
							></u--input>
						</u-form-item>
					</u--form>
				</view>
			</view>
			
		</view>
		<u-tabbar 
			:placeholder="true" 
			:safeAreaInsetBottom="true" 
			:borderTop="true"
		>
		    <u-button 
				v-if="orderDetails.payStatus == 1 ||orderDetails.payStatus == 0 "
				@click="playMent" 
				type="error" 
				text="提交订单"
				customStyle="width: 90%; margin: 10rpx auto;"
		    ></u-button>
			<text v-else class="status-text">{{ getStatusText(orderDetails.payStatus) }}</text>
		</u-tabbar>
		<u-toast ref="uToast"></u-toast> 
		<u-popup round="8" :show="storeShowAddress" mode="bottom"  @close="closeAddress" >
			<view class="popupBg">
				<nuoyu-address
					@settingAddress="settingAddress" 
					:addAddressShow="addAddressShow" 
					@delAddress="delAddress" 
					:addressList="addressList" 
					:colors="themeColor.main_color"
					>
				</nuoyu-address>
			</view>
		</u-popup>
		
		<u-popup 
			:show="couponsShow" 
			:round="10" 
			mode="bottom" 
			:closeOnClickOverlay="false"
			@close="couponsShow = false;radioValue=''"
			:closeable="true" 
			>
			<view class="coupon-container">
		        <view class="coupons_box" v-for="item in couponsData">	        	
					<view class="left">
						<view class="left_money">
							<span>￥</span>
							<span style="font-size: 50rpx;font-weight: bold;">{{ item.moneys }}</span>
						</view>
						<view><span style="color: #b0b0b2;font-size: 24rpx;">{{ {1:'满减',2:'口令',3:'指定'}[item.type] }}优惠券</span></view>
					</view>
					<view class="center">
						<view style="margin: 40rpx auto;">{{item.title}}</view>
					</view>
					<!-- && item.couponsNum == 1 -->
					<view class="right">
						<u-radio-group 
							v-if="item.my_status == '0' "
						    v-model="radioValue"
							style="margin: 46rpx auto;">
							<u-radio 
								:name="item.id"
								:key="item.id" 
								activeColor="red"
							>
							</u-radio>
						</u-radio-group>
						<view v-else style="margin: 46rpx auto;color: #b0b0b2;">不可用</view>
					</view>
		        </view>
			</view>
			<view>
				<u-button type="error" @click="submitRadio">确定</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
import aiGoodsAction  from "@/components/ai-goods-action/ai-goods-action.vue"
import echoneSku from '@/components/echone-sku/echone-sku.vue'
	export default{
		components:{
			aiGoodsAction
		},
		data(){
			return{
				serviceGuaranteeList:[],
				labelList:[],
				stock:1,
				addAddressShow:true,
				addressList:[],
				storeShowAddress:false,
				payVisible: false,
				money:0,
				specifications: [],
				combinations: [],
				popupShow:false,
				storeList:[],
				addressData:{},
				uuid:'',
				options:[
					{
						text:'客服',
						icon:'chat'
					},
					{
						text:'收藏',
						icon:'heart'
					},
					{
						text:'加入购物',
						icon:'cart',
						info:'0'
					}
				],
				buttons:{
					text:'立即购买',
					background:'',
				},
				timeData: {},
				currentNum:0,
				goodsDetails:{},
				orderDetails:{},
				list1: [],
				themeColor:"",
				screenWidth:0,
				screenHeight:0,
				storeShow:false,
				couponsShow:false,
				couponsData:[],
				selectCoupons:{},
				goods_id:'',
				order_id:'',
				count:0,
				businessId:'',
				quantity:1,
				optionsObj:'',
				wechatConfig:'',
				businessName:'',
				goodsSku:{},
				current: 0, 
				tabList: [
					{
						id:1,
				        name: '快递配送',
						class:'tabs_item_active'
				    }, {
						id:1,
				        name: '到店自提',
						class:'tabs_item_text'
				    }
				],
				typeShow:false,
				paypalCol: [
				    ['微信支付', '支付宝支付', '余额支付','月卡支付','积分支付']
				],
				goodsForm:{
					memo:'',
					paypal_type:null,
					actual_money:null,
					invoice:'',
				},
				radioValue:'',
			}
		},
		onLoad(options) {
			if(!uni.getStorageSync('userInfo').openid){
				uni.reLaunch({
					url:"/pages/tabbar/my"
				})
			}
			const info = uni.getSystemInfoSync();
			this.themeColor = this.$store.state.themeConfig || uni.getStorageSync('themeConfig')
			this.wechatConfig = this.$store.state.wechatConfig ||  uni.getStorageSync('wechatConfig')
			this.screenHeight = info.screenHeight;
			this.screenWidth = info.screenWidth
			this.buttons.background = this.themeColor.main_color
			let that = this
			this.getOrderDetails(options);
			this.getShoppingCartNum(options);
			if(options.businessId) this.getStore(options);
			this.optionsObj = options
			this.getCoupons()
			this.settingAddress()
		},
		computed:{
			goodsTypeText(){
				const typeMap={
					1:"微信支付",
					2:"支付宝支付",
					3:"余额支付",
					4:"月卡支付",
					5:"积分支付",
				}
				return typeMap[this.orderDetails.paypal_type]||"未知"
			},
			compPrice(){
				if(this.orderDetails.goods_info.goodsSkuType == '单规格'){
					var price = Number(this.orderDetails.goods_info.goodsPrice) * this.orderDetails.goodsQuantity
					if(this.selectCoupons.moneys){
						price -= this.selectCoupons.moneys
					}
					this.orderDetails.total_money = price
					this.orderDetails.goods_money = Number(this.orderDetails.goods_info.goodsPrice) * this.orderDetails.goodsQuantity
					return price
				}else{
					var price = Number(this.orderDetails.goods_sku.skuPrice) * this.orderDetails.goodsQuantity
					if(this.selectCoupons.moneys){
						price -= this.selectCoupons.moneys
					}
					this.orderDetails.total_money = price
					this.orderDetails.goods_money = Number(this.orderDetails.goods_sku.skuPrice) * this.orderDetails.goodsQuantity
					return price
				}
				
			}
		},
		methods:{
			changePay(e){
				const typeMap={
					1:"微信支付",
					2:"支付宝支付",
					3:"余额支付",
					4:"月卡支付",
					5:"积分支付",
				}
				if(e.value[0] == '微信支付'){
					this.orderDetails.paypal_type = 1
				}else if(e.value[0] == '支付宝支付'){
					this.orderDetails.paypal_type = 2
				}else if(e.value[0] == '余额支付'){
					this.orderDetails.paypal_type = 3
				}else if(e.value[0] == '月卡支付'){
					this.orderDetails.paypal_type = 4
				}else if(e.value[0] == '积分支付'){
					this.orderDetails.paypal_type = 5
				}
				
				this.typeShow = false
			},
			selectTabs(item,index){
				if(index == 0){
					item.class = 'tabs_item_active'
					this.tabList[1].class = 'tabs_item_text'
				}else{
					item.class = 'tabs_item_active1'
					this.tabList[0].class = 'tabs_item_text1'
				}
				 
			},
			changeTab(index) {
			    this.current = index.index;
			},
			joinShoppingCartSku(item){
				// this.uuid = e.id
				// this.stock = Number(e.count)
				// this.money = Number(e.price)
				this.stock = item.count
				this.popupShow = false;
				this.goodsSku = {
					id:item.id,
					value:item.name,
					image:item.image,
					price:item.price,
					stock:item.stock	
				}
				this.joinShoppingCart()
				// this.payVisible = true;
			},
			toStore(){
				uni.navigateTo({
					url:"/pages/goods/goodsStore?businessId="+this.businessId+"&businessName="+this.businessName
				})
			},
			// 购物车数量
			getShoppingCartNum(options){
				// let that = this 
				// that.tui.request("/basic-capi/shoppingCart/getShoppingCartNum", "get").then((res) => {
				// 	if(res.code == 200){
				// 		that.options[2].info = res.data.num
				// 		that.options[2].infoColor = this.themeColor.main_color
						
				// 	}
				// }).catch((res) => {
					 
				// })
			},
			// 优惠券列表
			getCoupons(){
				this.tui.request("/basic-capi/coupons/myCoupons", "get").then((res)=>{
					if(res.code == 200){
						if(res.data.list.length){
							// this.couponsData = res.data.list
							this.couponsData = res.data.list.map(item=>{
								if(item.item_id =='' && (item.moneys < this.goodsForm.actual_money)){
									 return {
									      ...item,         
									      couponsNum: 1      
									    };
								}else if(item.item_id == this.orderDetails.goods_id){
									 return {
									      ...item,         
									      couponsNum: 1     
									    };
								}else{
									return {
										...item,        
										couponsNum: 0     
									};
								}
							})
						}
						console.log("couponsData",this.couponsData)
					}
				})
			},
			// 订单详情
			getOrderDetails(options){
				
				if(options.order_id){
					let that = this;
					// 获取地址
					that.getAddress();
					// 获取商品销量
					that.order_id = options.order_id
					that.tui.request("/basic-capi/wechatApi/order/getOrderDetails", "get",{
						order_id:options.order_id
					}).then((res) => {
						if(res.code == 200){
							this.orderDetails = res.data.orderDetails
							this.orderDetails.goods_info = JSON.parse(this.orderDetails.goods_info)
							this.orderDetails.goods_info.previewUrl = this.wechatConfig.tencent‌Domain + this.orderDetails.goods_info.previewUrl
							if( this.orderDetails.goods_sku !=='') {
								this.orderDetails.goods_sku = JSON.parse(this.orderDetails.goods_sku)
								if(this.orderDetails.goods_info.distributionFee){
									this.goodsForm.actual_money = Number(this.orderDetails.goods_sku.skuPrice) + Number(this.orderDetails.goods_info.distributionFee)
								}
							} else if( this.orderDetails.goods_sku == '' && this.orderDetails.goods_info.distributionFee){
								this.goodsForm.actual_money =this.orderDetails.goods_info.goodsPrice + Number(this.orderDetails.goods_info.distributionFee)
							}
							console.log("res22",this.orderDetails)
						}
					}).catch((res) => {
						that.buttons.text = '立即购买'
					})
				}
			},
			serviceGuaranteeDetails(ids){
				this.tui.request("/basic-capi/serviceGuaranteeList/list", "get",
				{
					ids:JSON.parse(ids)
				}).then(res=>{
					 
					if(res.code == 200){
						this.serviceGuaranteeList = res.data.list
					} 
					
				})
			},
			goodsLabelList(ids){
				console.log(ids)
				this.tui.request("/basic-capi/mallGoodsLabel/list", "get",
				{
					ids:JSON.parse(ids),
					useType:'微信小程序'
				}).then(res=>{
					 
					if(res.code == 200){
						this.labelList = res.data.list
					} 
					
				})
			},
			getSales(goods_id){
				this.tui.request("/basic-capi/goods/getGoodsSales", "get",
				{
					goods_id:goods_id
				}).then(res=>{
					if(res.code == 200){
						this.count = res.data.count
					} 
					
				})
			},
			getAddress(){
				this.tui.request("/basic-capi/address/addressList", "get",{
					openid:uni.getStorageSync('userInfo').openid
				}).then(res=>{
					if(res.code == 200){
						this.addressList = res.data.list
					} 
				})
			},
			settingAddress(item,type,address){
				if(type == 'addSuccess'){
					this.getAddress();
				}
				this.addAddressShow = item;
				this.addressData = address
				this.storeShowAddress = false
			},
			delAddress(items){
				this.addressList = this.addressList.filter((item, index) => item.id !== items.id);
			},
			closeAddress(){
				this.storeShowAddress = false
			},
			getStore(options){
				this.tui.request("/basic-capi/store/getStore", "get",{
					pageNum:1,
					pageSize:10,
					businessId:this.businessId
				}).then((res) => {
					if(res.code == 200){
						this.storeList = res.data.list
						this.businessName = res.data.list[0].businessName
						this.storeList.forEach((item)=>{
							if(item.otherConfigJson){
								item.otherConfigJson =  JSON.parse(item.otherConfigJson)
								item.otherConfigJson.logo = this.wechatConfig.tencent‌Domain + item.otherConfigJson.logo
							}
						})
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			playMent(){
				if(this.addressData){
					this.business_info = this.orderDetails.business_info  // 商家
					this.goodsDetails = (this.orderDetails.goods_info) // 商品详情
					this.goods_id = this.goodsDetails.goods_id  // 商品id
					var order_data = {}
					var total_money = 0
					if(this.business_info){
						this.business_info = JSON.stringify(this.business_info)
					}
					else
						this.business_info = ''
					if(this.goodsDetails.goodsSkuType == '单规格'){
						// 计算总金额 
						total_money = (this.goodsForm.actual_money?this.goodsForm.actual_money:this.orderDetails.goods_info.goodsPrice) * this.orderDetails.goodsQuantity					
						order_data = {
							business_id:this.businessId,
							order_id:this.orderDetails.order_id,
							goods_id:this.goods_id,
							order_type:5,  // 5 余额订单
							paypal_type:3,  // 3余额支付
							goods_info:JSON.stringify(this.goodsDetails),
							user_info:JSON.stringify(uni.getStorageSync('userInfo')),
							business_info:this.business_info,
							goods_sku:'',
							type:'微信小程序',
							payStatus:this.orderDetails.payStatus,
							openid:uni.getStorageSync('userInfo')['openid'],
							goodsQuantity:this.orderDetails.goodsQuantity,
							memo:this.goodsForm.memo,
							coupon_id:this.selectCoupons.id || '',
							goodsSkuType:'单规格',
							address_id:this.addressData.id,
							distribution_type:"快递",
							total_money:total_money
						}
					}else if(this.goodsDetails.goodsSkuType == '多规格'){				
						total_money = ((this.goodsForm.actual_money?this.goodsForm.actual_money:this.orderDetails.goods_sku.skuPrice) * this.orderDetails.goodsQuantity)					
						 order_data = {
							order_id:this.orderDetails.order_id,
							business_id:this.businessId,
							goods_id:this.goods_id,
							order_type:5,
							paypal_type:3,
							address_id:this.addressData.id,
							goods_info:JSON.stringify(this.goodsDetails),
							user_info:JSON.stringify(uni.getStorageSync('userInfo')),
							business_info:this.business_info,
							goods_sku:this.orderDetails.goods_sku,
							type:'微信小程序',
							payStatus:this.orderDetails.payStatus,
							openid:uni.getStorageSync('userInfo')['openid'],
							goodsQuantity:this.orderDetails.goodsQuantity,
							memo:this.goodsForm.memo,
							coupon_id:this.selectCoupons.id || '',
							goodsSkuType:'多规格',
							distribution_type:"快递",
							total_money:total_money,
							goodsSkuJson:this.goodsDetails.goodsSkuJson
						}
					}else{
						uni.showToast({
							title:"规格错误!"
						})
					}
					this.tui.request("/basic-capi/wechatApi/order/order_confirm_status", "post",order_data).then(res=>{
						if(res.code == 200){
							this.tui.toast(res.message)
							
							console.log("res1",res)
							// this.getShoppingCartNum();
							setTimeout(()=>{
								uni.reLaunch({
									url:"/pages/goods/goodsSettlement"
								})
							},2000)
							
						}else{
							this.tui.toast(res.message)
						}
					})
				}else{
					this.$refs.uToast.show({
					    message: "请选择地址",
					    type: 'warning',
					});
				}
				
			},
			getStatusText(status){
				const statusMap = {
					// 0: '待支付',
					// 1: '确认订单',
					2: '支付中',
					3: '已支付',
					4: '待发货',
					5: '已发货',
					6: '待收货',
					7: '已收货',
					8: '已退款'
				};
				return statusMap[status] || '';
			},
			goPayClick() {
				this.payVisible = true;
			},
			successPayHandle(item,stock) {
				console.log(item,stock)
				this.quantity = stock;
				if(item=='微信'){
					uni.showToast({
						title:'暂不支持!'
					})
					return
				}
				if(item == '余额'){
					this.playMent();
				}
				
			},
			cancelPayHandle: function() {
				this.payVisible = false;
			},
			handleConfirm(e){
				this.uuid = e.id
				this.stock = Number(e.count)
				this.money = Number(e.price)
				this.popupShow = false;
				this.payVisible = true;
			},
			handleClose(){
				this.popupShow = false;
			},
			optionsClick(item){
				console.log(item)
				if(item.index == 2){
					this.joinShoppingCart();
				}
			},
			submitRadio(){
				if(this.radioValue != ''){
					this.selectCoupons = this.couponsData.find(item=>item.id == this.radioValue)
					// 使用优惠券的条件
					if(this.orderDetails.goods_info.goodsSkuType == '多规格'){
						if(Number(this.orderDetails.goods_sku.skuPrice)<Number(this.selectCoupons.moneys)){
							uni.showToast({
								title:"优惠券太大,不能超过金额"
							})
							return
						}
						
					}else{
						if(this.orderDetails.goods_info.goodsPrice<Number(this.selectCoupons.moneys)){
							
							uni.showToast({
								title:"优惠券太大,不能超过金额"
							})
							
						}
						
						
					}
					 
					
					 
					if((this.orderDetails.goods_sku.skuPrice>this.selectCoupons.moneys) || 
						(this.orderDetails.goods_info.goodsPrice>this.selectCoupons.moneys)
					){
						if(this.orderDetails.goods_info.goodsSkuType == '多规格'){
							this.goodsForm.actual_money = Number(this.orderDetails.goods_sku.skuPrice) - Number(this.selectCoupons.moneys) + Number(this.orderDetails.goods_info.distributionFee)
						}else{
							this.goodsForm.actual_money = Number(this.orderDetails.goods_info.goodsPrice) - Number(this.selectCoupons.moneys) + Number(this.orderDetails.goods_info.distributionFee)
						}
					}
					 
					this.couponsShow = false
				}
				
			},
			joinShoppingCart(){
				let that = this
				// that.goodsDetails
				let data = ''
				
				if(this.buttons.text == '立即支付'){
					data = {
						goods_id:that.goodsDetails.goods_id,
						goods_quantity:1,
						goods_price:that.goodsDetails.goodsPrice,
						goods_name:that.goodsDetails.goodsName,
						goods_image:that.goodsDetails.previewUrl,
						goods_subtitle:that.goodsDetails.subtitle,
						goods_sku:"",
						
					}
				}else{
					data = {
						goods_id:that.goodsDetails.goods_id,
						goods_quantity:this.stock,
						goods_price:this.goodsSku.price,
						goods_name:that.goodsDetails.goodsName,
						goods_image:that.goodsDetails.previewUrl,
						goods_subtitle:that.goodsDetails.subtitle,
						goods_sku:JSON.stringify(this.goodsSku),
					}
					
				}
				this.tui.request("/basic-capi/addUserShoppingCart/add", "post",data).then(res=>{
					if(res.code == 200){
						this.tui.toast('添加成功!')
						this.getShoppingCartNum();
					}else{
						this.tui.toast(res.message)
					}
				})
			},
			clickButton(item){
				this.money = this.goodsDetails.goodsPrice
				if(this.buttons.text == '立即支付'){
					this.goPayClick();
					return
				}
				this.popupShow = true;
			},
			close() {
				this.storeShow = false
			},
			onChange(e) {
				this.timeData = e
			}
		}
	}
</script>

<style lang="scss" scoped>
.nuoyu-index{
	height: 100%;
 	background: #f5f5f5;
	margin-top: 90rpx;
	background-color: #eee
}
.tabs_box{
	// width: 100%;
	// height:120rpx;
	// background: red;
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	// gap: 16rpx;
	padding: 12rpx;
	align-items: center;
	
}
.tabs_item_text{
	width: 94.5%;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #eee;
	padding: 12rpx;
	height: 60rpx;
	border-radius: 0rpx 16rpx 0rpx 0rpx;

}
.tabs_item_text1{
	width: 94.5%;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #eee;
	padding: 12rpx;
	height: 60rpx;
	border-radius: 16rpx 0px 0px 0px;

}
.tabs_item_active{
	width: 94.5%;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--main-bg-color);
	padding: 12rpx;
	color: white;
	animation:fadenum 0.25s 1;
	justify-content: center;
	align-items: center;
	height: 60rpx;
	border-radius: 16rpx 0px 0 0;
	
}
.tabs_item_active1{
	width: 94.5%;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--main-bg-color);
	padding: 12rpx;
	color: white;
	animation:fadenum 0.15s 1;
	justify-content: center;
	align-items: center;
	height: 60rpx;
	border-radius: 0px 16rpx 0px 0px;
}
@keyframes fadenum{
   from {
		width: 0%;
		color: transparent;
   }

   50% {
	   width: 80%;
	   color: transparent;
   }

   to {
	   width: 94.5%;
	   color: transparent;
   }
}
.address_box{
	display: flex;
	justify-content: space-between;
	padding:24rpx 16rpx;
	align-items: center;
	margin:-10.5rpx 12rpx;
	background-color: #eee;
	background: var(--main-bg-color);
	color: white;
	border-radius: 0 0 16rpx 16rpx;
	border-top: 1px solid #eee;
}
.goods_card{
	margin:12rpx;
	padding:16rpx;
	border: 1rpx solid #eee;
	border-radius: 16rpx;
	background-color: #fff;
}
.goods_card .card_top{
	display: flex;
}
.left_img{
	width: 30%;
	display: flex;
	justify-content: center;
}
.right_text{
	display: flex;
	flex-direction: column;
	width: 70%;
}
.right_text view{
	margin: 5rpx 0;
}
.right_text .text_title{
	width: 100%;
	font-size: 36rpx;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis
}
.text_number{
	width: 100%;
	display: flex;
	justify-content: space-between;
}
.text_number span{
	width: 50%;
}
.text_number span:first-child{
	font-weight: bold;
	font-size: 38rpx;
}
.goods_info{
	margin: 5rpx 12rpx;
	padding:16rpx;
	border: 1rpx solid #eee;
	border-radius: 16rpx;
	background-color: #fff;
}
.popupBg{
	height: 60vh;
	padding: 20rpx;
	overflow-y: auto;
}
.form-item-align {
  display: flex;
  justify-content: space-between;
}
.coupon-container{
	margin-top: 56rpx;
	max-height: 500rpx;
	overflow-y: auto;
}
.coupons_box{
	margin: 10rpx;
	border: 1rpx solid #eee7eb;
	border-radius: 16rpx;
	display: flex;
}
.coupons_box .left{
	width: 30%;
	margin: 5rpx auto;
	text-align: center;
}
.coupons_box .left_money{
	color: red;
}
.coupons_box .center{
	width: 50%;
}
.coupons_box .right{
	width: 20%;
}
.u-toast__content {
  color: transparent !important;
  font-size: 0 !important;
}
.status-text {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  font-size: 40rpx;
}
</style>